package cn.zhaoguang.usedcar.main.controller;

import cn.zhaoguang.usedcar.common.http.ResultVO;
import cn.zhaoguang.usedcar.main.entity.Carousel;
import cn.zhaoguang.usedcar.main.service.CarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/7/7 10:33
 */
@RestController
@RequestMapping("/carousel")
@Api(tags = "轮播图控制器")
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    @PostMapping("/add")
    @ApiOperation(value = "添加", notes = "添加轮播图")
    public ResultVO add(@RequestBody Carousel carousel) {
        int result = carouselService.add(carousel);
        if (result > 0) {
            return ResultVO.success("添加成功");
        }
        return ResultVO.error("添加失败，此车辆已存在轮播图中");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", notes = "删除轮播图")
    public ResultVO delete(@PathVariable("id") Integer id) {
        int result = carouselService.delete(id);
        if (result > 0) {
            return ResultVO.success("删除成功");
        }
        return ResultVO.error("删除失败");
    }

    @GetMapping("/findAllCarousel")
    @ApiOperation(value = "查询全部轮播图", notes = "查询全部轮播图")
    public ResultVO findAll() {
        return ResultVO.success("查询成功", carouselService.findAll());
    }
}
